Part 32: FredMSloniker - Hex Wars Redux - Part 2
Tuning up Hex War: Part 2When you start a game of Hex War, you're presented with a screen that looks something like this. (If you're playing with capital cities, they appear as crosses.) The purple forces are arranged at the bottom, and the blue forces at the top. Purple always gets the first -
- wait, purple and yellow versus blue and green? Who chose these team colors? A big Seahawks and Huskies fan? What if I don't like these options?
Fortunately, it's not too difficult to fix. We just have to hack the code a bit. But first, a picture.
These are the 16 colors available to us on a Commodore 64. Before we can change the colors of the armies, we have to first locate where those colors are in the code. There are three forms in which they show up:
- Various calculations are used to set the cursor color (i.e., the color that the PRINT command will use next) either blue or purple. A calculation is also used to set the screen border blue or purple, depending on whose turn it is.
- Victory text calls out blue or purple by name.
- Two strings are defined describing the shape of the pieces; these strings have color codes baked in. (Note: this is the only place the yellow and green colors are used.) The colors are also hard-coded into the Hex War banner that appears while the game is getting started.
At some point, I should probably allow players to choose their piece colors, but for right now I added some constants that we can change to change the army colors. The first point at which the colors matter is line 60, which defines strings that we print to make the units. We get there from line 50, which means we have nine lines worth of room to work with. Here's the code:
code:
51 P0=4:P1=6:P2=13:P3=7:REM DEFAULT ARMY COLORS
52 PC$="{black}{white}{red}{cyan}{purple}{green}{blue}{yellow}
{orange}{brown}{lt. red}{gray1}{gray2}{lt. green}{lt. blue}{gray3}"
53 C0$=MID$(PC$,P0+1,1):C1$=MID$(PC$,P1+1,1)
54 C2$=MID$(PC$,P2+1,1):C3$=MID$(PC$,P3+1,1)
55 DATA"BLACK","WHITE","RED","CYAN","PURPLE","GREEN","BLUE","YELLOW"
56 DATA"ORANGE","BROWN","PINK","DK.GRAY","MD.GRAY","LIME","INDIGO","LT.GRAY"
57 DIMPC$(15):FORZZ=0TO15:READPC$(ZZ):NEXT
58 N0$=PC$(P0):N1$=PC$(P1)
So, let's explain. Line 51 is where we set the army colors; P0 and P1 are the primary colors of the two players (player 2 is player 0 internally), while P2 and P3 are the secondary colors of players 0 and 1, respectively.
Line 52 isn't actually full of curly brackets; it contains the 16 color codes used by the Commodore 64 to change colors while printing. Lines 53 and 54 grab the codes associated with the numbers in P0 to P3 and assign them to C0$ to C3$ respectively.
Lines 55 and 56 contain names for the 16 colors, which are read into an array in line 57. Then line 58 puts the names for the two primary colors into N0$ and N1$.
So now I had all the bits I needed. Where did I put them in the program? As I said, the first occurence is line 60:
code:
60 A=RND(-TI/97):P0$="{blue}{rvrs off}{$af:2}{down}{left:2}{lt. green}{$df}
{ctrl pound}":P1$="{yellow}{rvrs on}{ctrl pound}{$df}{rvrs off}{down}
{left:2}{purple}{$b7:2}"
code:
60 A=RND(-TI/97):P0$=C0$+"{rvrs off}{$af:2}{down}{left:2}"+C2$+"{$df}
{ctrl pound}":P1$=C3$+"{rvrs on}{ctrl pound}{$df}{rvrs off}{down}{left:2}"
+C1$+"{$b7:2}"
code:
310 XC=6:YC=11:GOSUB1:PRINTC0$;"{rvrs on} {$cc}{$a7} {$cc}{$b7} {$cd}
{$ce} {$a5}{$a7} {$ce}{$cd} {$cf}{$cd} "
320 XC=6:YC=12:GOSUB1:PRINTC1$;"{rvrs on} {$a5}{$a7} {$cc}{$af} {$ce}
{$cd} {$ce}{$cd} {$cf}{$a7} {$a5}{$cd} {home}{red}{rvrs off}";
code:
430 POKEC4,P0+PN*(P1-P0):GOSUB800:REM JOYSTICK
Lines 680 and 690 set the cursor color before drawing the capital cities, if we're playing a game mode with capital cities:
code:
680 J=1:POKEC5,P0:IFGN=1THENC$=D$:GOSUB710:J=2:POKEC5,P1:GOSUB710
690 IFGN=2THENC$=D$:GOSUB710:J=3:POKEC5,P0:GOSUB710
code:
910 POKEC5,P0+Q1*(P1-P0):PRINT"{home}"QN:PRINT"{$c0:6}{rvrs off}{gray2}"
code:
1540 DATA 64,2,8,64,3,7,64,5,6,64,6,6:REM PLAYER 1
1550 DATA 64,2,2,64,3,2,64,5,1,64,6,0:REM PLAYER 0
code:
1860 POKEC5,P0+A*(P1-P0):XC=E:YC=F+A:GOSUB1
code:
3430 IFMAP(CIT(2,0),CIT(2,1),1)=1THENA=2:C$=N1$+" CAPTURED THE CAPITAL":RETURN
3450 IFMAP(CIT(3,0),CIT(3,1),1)=1THENA=2:C$=N1$+" CAPTURED THE CAPITAL":RETURN
3460 IFMAP(CIT(1,0),CIT(1,1),1)=2THENA=1:C$=N0$+" CAPTURED THE CAPITAL"
3550 IF C(1)=> L THEN A=2:C$=N0$+" HAS CAPTURED"+STR$(C(1))+" CITIES":RETURN
3560 IF C(2)=> L THEN A=1:C$=N1$+" HAS CAPTURED"+STR$(C(2))+" CITIES"
3620 IF C(1)=>40THENA=2:C$=N0$+" OCCUPIES"+STR$(C(1))+" HEXES":RETURN
3630 IF C(2)=>40THENA=1:C$=N1$+" OCCUPIES"+STR$(C(2))+" HEXES"
Now, this first pass does have some flaws. Obviously it would be possible to choose colors that would make pieces invisible or look the same, but that's down to user error at this point. It also doesn't do anything about potential conflicts with the other colors used; for instance, the border changes colors between turns to indicate that the computer is processing. That's something I planned to tweak later.
I gave it a try by changing this line:
code:
51 P0=2:P1=6:P2=10:P3=14
...oops.
To do list:
- Fix the bug(s) I've introduced.
- Fix the victory reporting code; right now it doesn't distinguish between occupying or controlling cities, even though the code correctly checks this depending on game mode. (I noticed this while putting in the color names in 3550-3630.)
- Make player piece color chooseable in game.
- Handle conflicts between player piece colors and other colors used in game.
- Make the random reinforcements fair, or at least more fair.
- Look for other ways game can be improved.